package com.zhenhao.xsq.ui.activity.camera;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.example.zhouwei.library.CustomPopWindow;
import com.orhanobut.logger.Logger;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.application.AppConfig;
import com.zhenhao.xsq.base.BaseActivity;
import com.zhenhao.xsq.ui.activity.camera.component.DaggerCameraPlayComponent;
import com.zhenhao.xsq.ui.activity.camera.contract.CameraPlayContract;
import com.zhenhao.xsq.ui.activity.camera.module.CameraPlayModule;
import com.zhenhao.xsq.ui.activity.camera.presenter.CameraPlayPresenter;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;


/**
 * @author xlei
 * @Package com.cxwl.xlxgj.ui.activity.monitor
 * @Description: $description
 * @date 2019/04/22 16:04:57
 */

public class CameraPlayActivity extends BaseActivity implements CameraPlayContract.View{

    @Inject
    CameraPlayPresenter mPresenter;


    @Override
    protected void initView() {
        setContentView(R.layout.activity_camera_paly);
        ButterKnife.bind(this);
        //        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // 保持屏幕常亮
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


        autolayout.setBackgroundColor(ContextCompat.getColor(this, R.color.black));
        mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.black));
        toolbarTitle.setTextColor(ContextCompat.getColor(this, R.color.white));
        mToolbar.setNavigationIcon(R.mipmap.toolbar_back);

    }

    @Override
    protected void initData() {

    }


    @Override
    protected void onResume() {
        super.onResume();
//        if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
//            return;
//        }
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                if (mRealPlaySv != null) {
//                    InputMethodManager imm = (InputMethodManager) getSystemService(Context
//                            .INPUT_METHOD_SERVICE);
//                    imm.hideSoftInputFromWindow(mRealPlaySv.getWindowToken(), 0);
//                }
//            }
//        }, 200);
//        Logger.i("onResume real play status:" + mStatus);
//        if (mStatus == RealPlayStatus.STATUS_INIT || mStatus == RealPlayStatus.STATUS_PAUSE
//                || mStatus == RealPlayStatus.STATUS_DECRYPT) {
//            // 开始播放
//            startRealPlay();
//        }
//        mIsOnStop = false;
    }

    @Override
    protected void onStop() {
        super.onStop();
//        if (mStatus != RealPlayStatus.STATUS_STOP) {
//            mIsOnStop = true;
//            stopRealPlay();
//            mStatus = RealPlayStatus.STATUS_PAUSE;
//        } else {
//            progress.setVisibility(View.GONE);
//        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if (mEZPlayer != null) {
//            mEZPlayer.release();
//        }
//        mHandler = null;
//        if (mBroadcastReceiver != null) {
//            // 取消锁屏广播的注册
//            unregisterReceiver(mBroadcastReceiver);
//            mBroadcastReceiver = null;
//        }
//        if (subscribe != null) {
//            subscribe.dispose();
//            //记录当前播放的时间 比对时间间隔
//            SPUtils.getInstance().put("time" + position, System.currentTimeMillis());
//        }
    }

    @Override
    protected void setupActivityComponent() {
        DaggerCameraPlayComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .cameraPlayModule(new CameraPlayModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void setPresenter(CameraPlayContract.CameraPlayContractPresenter presenter) {
        mPresenter = (CameraPlayPresenter) presenter;
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

}